<?php
include_once("../../../common/module/checkA.php");
include_once("../../../../config.php");
include_once("../controller/term-list.php");




?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <? include_once(ROOT_PATH_ . "/controller/common/module/head.php"); ?>

</head>

<body>

<div id="topbar">
    <?php include ROOT_PATH_ . '/controller/common/module/topbar.php'; ?>
</div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_ . '/controller/common/module/sidebar.php'; ?>
        </div>


        <div id="content">
            <?php $page_title = '分类列表'; ?>
            <?php include ROOT_PATH_ . '/controller/common/module/mod-page-title.php'; ?>

            <!-- 用$system_part .list_boxes来控制来到确认板块信息显示-->
            <div class="list-box">
                <div class="list-boxes">
                    <table class="layui-table">
                        <colgroup>

                            <col width="80">
                            <col width="100">
                            <col>
                            <col>
                            <col width="200">
                        </colgroup>
                        <thead>
                        <tr>

                            <th>序号</th>
<!--                            <th>图片</th>-->
                            <th>名称</th>
                            <th>分类</th>
                            <th>发布状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>

                        <?php

                        for($i=0;$i<count($termlist);$i++)
                        {

                            $cat_list = implode(',',get_cat_child($termlist[$i]['nid'],$system_part));

                            $result = mysql_query("select count(*) as number from ".$table_Prefix."relation where term_nid in ($cat_list)");

                            $now_product_number = mysql_fetch_assoc($result);

                            ?>
    <tr>
        <td>
   <?echo $i+1;?>
        </td>


        <!--
        <td align="center">
            <img
                src="/uploadfiles/uf<? echo $site['mid'] ?>/<?php echo $termlist[$i]['icon'] ?>"
                width="50"/>
        </td>
-->

        <td align="center">
            <a href="term-edit.php?nid=<?php echo $termlist[$i]['nid'] ?>&now_extender=<? echo $system_part ?>&nowpageid=<? echo $_REQUEST['nowpageid'] ?>&sortby=<? echo $_REQUEST['sortby'] ?>" <? if ($termlist[$i]['publish'] != 1) {
                echo "class='title-notice'";
            } ?> >
                 <?php echo $termlist[$i]['name'] ?>
            </a>
        </td>

        <td>
            <?php echo $termlist[$i]['interm'] ?>
        </td>

        <td>
            <? if ($termlist[$i]['publish'] == 1) {
                echo "是";
            } else {
                echo "否";
            } ?>
        </td>

        <td>

            <a class="delete layui-btn  layui-btn-sm" <?php if ($termlist[$i]['is_disabled'] == 1 || $now_product_number['number'] > 0) {
                echo 'style= background:#ccc;cursor:not-allowed; ' . ' href="javascript:void(0)"';
            } else {
                echo 'href="term-delete.php?nid=' . $termlist[$i]['nid'] . '&now_extender=' . $system_part . '"';
            } ?> ><i class="layui-icon">&#xe640;</i>删除</a>

            <a href="term-edit.php?nid=<?php echo $termlist[$i]['nid'] ?>&nav-itemed=product&nowpageid=<? echo $_REQUEST['nowpageid'] ?>&sortby=<? echo $_REQUEST['sortby'] ?>"
               class="modify layui-btn  layui-btn-sm"><i class="layui-icon">&#xe642;</i>修改</a>

        </td>
    </tr>

    <?

    //设置需要搜索的表格的前缀后缀
    $table_suffix = $sys_term_table;
    $table        = $table_Prefix . $table_suffix;
    //设置需要搜索的表格的前缀后缀


    //设置需要搜索的表格的排序项和升降项
    $sort_by    = "nid";
    $sort_order = "desc";
    //设置需要搜索的表格的排序项和升降项

    ?>
    <?

    $query2   = mysql_query("SELECT COUNT(nid) FROM $table where term1 = " . $termlist[$i]['nid'] . " && interm = 'term1' and belong = '$sys_belong'");
    $term1sum = mysql_result($query2, 0);

    if ($_REQUEST ['sortby']) {
        $sort_by = $_REQUEST ['sortby'];
    }

    $result1 = mysql_query("select * from $table where term1 = " . $termlist[$i]['nid'] . " && interm = 'term1' and belong = '$sys_belong' ORDER BY $sort_by $sort_order");

    $term1 = array();
    while ($row1 = mysql_fetch_assoc($result1)) {
        $term1[]          = $row1;
        $term1_icon[$i][] = $row1['icon'];

    }


    ?>
    <?php


    for ($ii = 0; $ii < $term1sum; $ii++) {

        $cat_list = implode(',', get_cat_child($term1[$ii]['nid'], $system_part));

        $result = mysql_query("select count(*) as number from " . $table_Prefix . "relation where term_nid in ($cat_list)");

        $now_product_number2 = mysql_fetch_assoc($result);

        ?>
        <tr>
            <td align="center">
                <img
                    src="../../uploadfiles/uf<? echo $site['mid'] ?>/<?php echo $term1[$i]['icon'] ?>"
                    width="50"/>
            </td>

            <td>                <a href="term-edit.php?nid=<?php echo $term1[$ii]['nid'] ?>&now_extender=<? echo $system_part ?>&nowpageid=<? echo $_REQUEST['nowpageid'] ?>&sortby=<? echo $_REQUEST['sortby'] ?>" <? if ($term1[$ii]['publish'] != 1) {
                    echo "class='title-notice'";
                } ?> >
                        <span style="font-size: 18px"><?php echo $termlist[$i]['name'] ?>
                            - <?php echo $term1[$ii]['name'] ?></span>
                </a>
            </td>


            <td>

            </td>

            <td>

                <a class="delete layui-btn  layui-btn-sm" <?php if ($term1[$ii]['is_disabled'] == 1 || $now_product_number2['number'] > 0) {
                    echo 'style= background:#ccc;cursor:not-allowed; ' . ' href="javascript:void(0)"';
                } else {
                    echo 'href="term-delete.php?nid=' . $term1[$ii]['nid'] . '&now_extender=' . $system_part . '"';
                } ?> ><i class="layui-icon">&#xe640;</i>删除</a>
                <a href="term-edit.php?nid=<?php echo $term1[$ii]['nid'] ?>&now_extender=<? echo $system_part ?>&nowpageid=<? echo $_REQUEST['nowpageid'] ?>&sortby=<? echo $_REQUEST['sortby'] ?>"
                   class="modify layui-btn  layui-btn-sm"><i class="layui-icon">
                        &#xe642;</i>修改</a>

            </td>
        </tr>
        <?

        $term1idnow = $term1[$i]['nid'];

        $query    = mysql_query("SELECT COUNT(nid) FROM $table where term2 = $term1idnow && interm = 'term2' and belong = '$sys_belong'");
        $term2sum = mysql_result($query, 0);


        $result2 = mysql_query("select * from $table where term2= $term1idnow && interm = 'term2' and belong = '$sys_belong' ORDER BY $sort_by $sort_order");

        $term2 = array();
        while ($row2 = mysql_fetch_assoc($result2)) {

            $term2_icon[] = $row2['icon'];
            $term2[]      = $row2;

        }

        ?>
        <?php
        for ($iii = 0; $iii < $term2sum; $iii++) {
            $cat_list = implode(',', get_cat_child($term2[$iii]['nid'], $system_part));

            $result = mysql_query("select count(*) as number from " . $table_Prefix . "relation where term_nid in ($cat_list)");

            $now_product_number3 = mysql_fetch_assoc($result);
            ?>
            <tr>
                <td align="center">
                    <img
                        src="../../uploadfiles/uf<? echo $site['mid'] ?>/<?php echo $term2[$i]['icon'] ?>"
                        width="50"/>
                </td>

                <td>
                    <div class="name" style="margin-bottom: 15px;">
                        <label>分类名称：</label>
                        <a href="term-edit.php?nid=<?php echo $term2[$iii]['nid'] ?>&now_extender=<? echo $system_part ?>&nowpageid=<? echo $_REQUEST['nowpageid'] ?>&sortby=<? echo $_REQUEST['sortby'] ?>" <? if ($term2[$iii]['publish'] != 1) {
                            echo "class='title-notice'";
                        } ?> >
                            <span style="font-size: 18px"><?php echo $termlist[$i]['name'] ?>
                                - <?php echo $term1[$ii]['name'] ?>
                                - <?php echo $term2[$iii]['name'] ?></span>
                        </a>
                    </div>


                    <div class="date">
                        <? if ($term2[$iii]['modifytime']) { ?>
                            <span class="modifytime">
<label>修改时间：</label><? echo $term2[$iii]['modifytime'] ?>
</span>
                        <?php } ?>

                        <span class="publish <? if ($term2[$iii]['publish'] != 1) {
                            echo "title-notice";
                        } ?>">
<label>发布状态：</label><? if ($term2[$iii]['publish'] == 1) {
                                echo "是";
                            } else {
                                echo "否";
                            } ?>
</span>

<span class="clickrate">
<label>点击次数：</label><? echo $term2[$iii]['clickrate'] ?>
</span>

<span class="product_number">
<label>产品数量：</label>
<a href="detail-list.phpnow_extender=product&nid=<?php echo $term2[$iii]['nid'] ?>">

<?
echo $now_product_number3['number'];
?>
</a>
</span>

                    </div>
                </td>

                <td>

                    <a class="delete layui-btn  layui-btn-sm" <?php if ($term2[$iii]['is_disabled'] == 1 || $now_product_number3['number'] > 0) {
                        echo 'style= background:#ccc;cursor:not-allowed; ' . ' href="javascript:void(0)"';
                    } else {
                        echo 'href="term-delete.php?nid=' . $term2[$iii]['nid'] . '&now_extender=' . $system_part . '"';
                    } ?> ><i class="layui-icon">&#xe640;</i>删除</a>


                    <a href="term-edit.php?nid=<?php echo $term2[$iii]['nid'] ?>&now_extender=product&nowpageid=<? echo $_REQUEST['nowpageid'] ?>&sortby=<? echo $_REQUEST['sortby'] ?>"
                       class="modify layui-btn  layui-btn-sm"><i class="layui-icon">&#xe642;</i>修改</a>

                </td>
            </tr>
                                    <?php
                                }
                            }

                        } ?>

                        </tbody>
                    </table>






                </div>



                <div class="list-box-function"
                    <? if ($detailnum == 0) {
                        echo "style" . "='display:none'";
                    } ?>
                    >

                    <?php include 'page_numbers.php'; ?>

                </div>
            </div>


            <!--list-box end-->
        </div>

        <!--content端點01-->
    </div>
    <!--maincontent端點01-->
    <br class="clearfloat"/>
</div>
<!--container端點01-->
</div>







<!--删除box-->
<?php include '../module/deletebar.php'; ?>
<!--删除box end-->

<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?> </body>
</html>
